var log4js = require('log4js');

var config = {
    development: {
        port: 4201,
        domain: 'http://127.0.0.1:4201',
        path: 'build',
        wx: {
            jsdebug: true
        },
        apiBase: 'http://192.168.0.222:8800',
        // apiBase: 'http://192.168.0.41:8800/daily-web',
        apis: {
            jinlilai: 'http://192.168.0.222:8800'
        },
        oauth: {
            wxAuthorize: 'http://wx.ngrok.fongwell.com/wx/oauth',
            serverClientId: 'KatdGR3yyc8WDYQBxVjcIfuPDHmgwUmf',
            serverClientSecret: 'i4RofI38ryzdIzDy6N3XHtCNAhTQR1lXV8VuFZjqEPhWya5DEWkhcCHowqdvhVuX',
            serverAccessTokenUrl: 'http://192.168.0.222:8022/oauth/token',
            defaultClient: 'fongwell',
            redirectUrl: 'http://wx.ngrok.fongwell.com/',
            accessTokenUrl: '/access_token',
            passportStrategy: 'fwJwt'
        },
        token: {
            cookie: {
                name: 'fwdaily.token',
                path: '/',
                maxAge: 1000 * 60 * 60 * 2,
                httpOnly: true,
                secure: false,
                signed: false
            }
        },
        log4js: {
            configure: function () {
                log4js.configure({
                    appenders: [{
                        type: 'console',
                        category: 'site'
                    }, {
                        type: 'console',
                        category: 'express'
                    }]
                });
            },
            express: function (app, logger) {
                app.use(log4js.connectLogger(logger, {
                    level: log4js.levels.DEBUG
                }));
            }
        }
    },
    production: {
        port: 3330,
        domain: 'http://daily.web.v3.fongwell.com',
        path: 'build',
        apiBase: 'http://daily.api.fongwell.com',
        wx: {
            jsdebug: false
        },
        apis: {
            jinlilai: 'http://daily.api.jinlilai.fongwell.com'
        },
        oauth: {
            wxAuthorize: 'http://sso.fongwell.com/wx/oauth',
            serverClientId: 'KatdGR3yyc8WDYQBxVjcIfuPDHmgwUmf',
            serverClientSecret: 'i4RofI38ryzdIzDy6N3XHtCNAhTQR1lXV8VuFZjqEPhWya5DEWkhcCHowqdvhVuX',
            serverAccessTokenUrl: 'http://sso.fongwell.com/oauth/token',
            defaultClient: 'fongwell',
            redirectUrl: 'http://daily.web.v3.fongwell.com',
            accessTokenUrl: '/access_token',
            passportStrategy: 'fwWx' //fwJwt
        },
        token: {
            cookie: {
                name: 'fwdaily.token',
                path: '/',
                maxAge: 1000 * 60 * 60 * 2,
                httpOnly: true,
                secure: false,
                signed: false
            }
        },
        log4js: {
            configure: function () {
                log4js.configure({
                    appenders: [{
                        type: 'console',
                        category: 'site'
                    }, {
                        type: 'console',
                        category: 'express'
                    }],
                    levels: {
                        site: 'warn' //trace, debug, info, warn, error, fatal
                    }
                });
            },
            express: function (app, logger) {
                app.use(log4js.connectLogger(logger, {
                    level: log4js.levels.WARN
                }));
            }
        }
    },
    prodtest: {
        port: 3331,
        domain: 'http://daily.web.v3.test.fongwell.com',
        path: 'build',
        apiBase: 'http://daily.api.nightly.fongwell.com',
        wx: {
            jsdebug: true
        },
        apis: {
            jinlilai: 'http://daily.api.nightly.fongwell.com'
        },
        oauth: {
            wxAuthorize: 'http://sso.fongwell.com/wx/oauth',
            serverClientId: 'KatdGR3yyc8WDYQBxVjcIfuPDHmgwUmf',
            serverClientSecret: 'i4RofI38ryzdIzDy6N3XHtCNAhTQR1lXV8VuFZjqEPhWya5DEWkhcCHowqdvhVuX',
            serverAccessTokenUrl: 'http://sso.fongwell.com/oauth/token',
            defaultClient: 'fongwell',
            redirectUrl: 'http://daily.web.v3.test.fongwell.com',
            accessTokenUrl: '/access_token',
            passportStrategy: 'fwJwt' //fwWx
        },
        token: {
            cookie: {
                name: 'fwdaily.token',
                path: '/',
                maxAge: 1000 * 60 * 60 * 2,
                httpOnly: true,
                secure: false,
                signed: false
            }
        },
        log4js: {
            configure: function () {
                log4js.configure({
                    appenders: [{
                        type: 'console',
                        category: 'site'
                    }, {
                        type: 'console',
                        category: 'express'
                    }]
                });
            },
            express: function (app, logger) {
                app.use(log4js.connectLogger(logger, {
                    level: log4js.levels.DEBUG
                }));
            }
        }
    },
};
var envbuild = 'development';
if (process.env.config_env) {
    envbuild = process.env.config_env;
} else {
    if (process.argv.length > 2) {
        for (var i in config) {
            if (process.argv.indexOf(i) !== -1) {
                envbuild = i;
                break;
            }
        }
    }
}

var toUse = config[envbuild];
console.log('配置环境:' + envbuild);
module.exports = toUse;